﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LocalizedResources;


namespace ConsoleDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            DataAnnotationsLocalizer.SetDefaultResourceType(typeof(Person).Assembly, typeof(DisplayNames), typeof(DisplayAttribute));
            DataAnnotationsLocalizer.SetDefaultResourceType(typeof(Person).Assembly, 
                typeof(ErrorMessages),
                typeof(RequiredAttribute), 
                typeof(MaxLengthAttribute));

            DataAnnotationsLocalizer.ReplaceDefaultLocalizedMessage<RequiredAttribute>(
                typeof(Person).Assembly, typeof(Person).Namespace, typeof(ErrorMessages), ErrorMessages.Keys.RequiredMessage);
            DataAnnotationsLocalizer.ReplaceDefaultLocalizedMessage<MaxLengthAttribute>(
                typeof(Person).Assembly, typeof(Person).Namespace, typeof(ErrorMessages), ErrorMessages.Keys.MaxLengthMessage);


            try
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-de");
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-de");

                Person p = new Person { Address = "asdkjalsdkjalskdjasldkjalskdjaskldjaskldjalasdasdasdasdasdasdskdjalskdjaskldjalsdkjalsdk" };

                List<ValidationResult> res = new List<ValidationResult>();
                Validator.TryValidateObject(p, new ValidationContext(p, null, null), res, true);

                foreach (var item in res)
                {
                    Console.WriteLine(item.ErrorMessage);
                }
            }
            catch (ValidationException)
            {

            }

            Console.ReadLine();

        }
    }
}
